package com.kzj.mls.recyclerCard.cardView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kzj.mls.R;
import com.kzj.mls.beans.OrderDetailsBean;
import com.kzj.mls.global.App;
import com.kzj.mls.recyclerCard.basic.CardItemView;
import com.kzj.mls.recyclerCard.card.other.OrderDetailsCard;
import com.kzj.mls.recyclerCard.card.other.ServiceCard;
import com.kzj.mls.util.ImageUtil;

/**
 * Created by xyg on 2015/10/26.
 */
public class OrderDetailsCardView extends CardItemView<OrderDetailsCard> {
    private OrderDetailsBean orderDetailsBean;
    private Context context;
    private TextView textView_type;
    private TextView textView_sn;
    private TextView textView_status;
    private ImageView imageView_logo;
    private TextView textView_goods_name;
    private TextView textView_goods_amount;
    private TextView textView_order_amount;
    private TextView textView_time;
    private TextView textView_address;
    private TextView textView_phone;
    private TextView textView_remarks;
    private TextView textView_add_time;
    private LinearLayout linearlayout_evaluate;
    private ImageView imageView_start1;
    private ImageView imageView_start2;
    private ImageView imageView_start3;
    private ImageView imageView_start4;
    private ImageView imageView_start5;
    private TextView textView_evaluate;
    private TextView textView_call;
    private TextView textView_complete;
    private TextView textView_sure;
    private TextView textView_tv1;
    private static final String STORE = "2";
    private static final String ADDRESS = "1";
    private static final String SERVICE = "30";//待服务
    private static final String CONFIRM = "25";//待确认
    private static final String CANCEL = "0";//已取消
    private static final String COMPLETE = "40";//已完成
    private static final String Evaluation = "1";//有评价
    private static final String Not_Evaluation = "0";//无评价
    private LinearLayout linearLayout_evaluate;

    public OrderDetailsCardView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public OrderDetailsCardView(Context context) {
        super(context);
        this.context = context;
    }

    public OrderDetailsCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    @Override
    public void build(final OrderDetailsCard card) {
        super.build(card);
        orderDetailsBean = card.getOrderDetails();
        textView_type = (TextView) findViewById(R.id.textView_type);
        textView_sn = (TextView) findViewById(R.id.textView_sn);
        textView_status = (TextView) findViewById(R.id.textView_status);
        imageView_logo = (ImageView) findViewById(R.id.imageView_logo);
        textView_goods_name = (TextView) findViewById(R.id.textView_goods_name);
        textView_goods_amount = (TextView) findViewById(R.id.textView_goods_amount);
        textView_order_amount = (TextView) findViewById(R.id.textView_order_amount);
        textView_time = (TextView) findViewById(R.id.textView_time);
        textView_address = (TextView) findViewById(R.id.textView_address);
        textView_phone = (TextView) findViewById(R.id.textView_phone);
        textView_remarks = (TextView) findViewById(R.id.textView_remarks);
        textView_add_time = (TextView) findViewById(R.id.textView_add_time);
        linearlayout_evaluate = (LinearLayout) findViewById(R.id.linearlayout_evaluate);
        imageView_start1 = (ImageView) findViewById(R.id.imageView_start1);
        imageView_start2 = (ImageView) findViewById(R.id.imageView_start2);
        imageView_start3 = (ImageView) findViewById(R.id.imageView_start3);
        imageView_start4 = (ImageView) findViewById(R.id.imageView_start4);
        imageView_start5 = (ImageView) findViewById(R.id.imageView_start5);
        textView_evaluate = (TextView) findViewById(R.id.textView_evaluate);
        textView_call = (TextView) findViewById(R.id.textView_call);
        textView_complete = (TextView) findViewById(R.id.textView_complete);
        textView_sure = (TextView) findViewById(R.id.textView_sure);
        textView_tv1 = (TextView) findViewById(R.id.textView_tv1);
        linearLayout_evaluate = (LinearLayout) findViewById(R.id.linearLayout_evaluate);
        textView_type.setText(orderDetailsBean.getSite_type_lang());
        textView_sn.setText(orderDetailsBean.getOrder_sn());
        App.displayImageHttpOrFile(orderDetailsBean.getGoods_image(), imageView_logo, ImageUtil.OptionsNormal());
        textView_goods_name.setText(orderDetailsBean.getGoods_name());
        textView_goods_amount.setText(orderDetailsBean.getGoods_amount());
        textView_order_amount.setText(orderDetailsBean.getOrder_amount());
        textView_time.setText("预约时间：" + orderDetailsBean.getMake_time());
        textView_address.setText("预约地点：" + orderDetailsBean.getAddress());
        textView_phone.setText("客户电话：" + orderDetailsBean.getPhone_mob());
        textView_status.setText(orderDetailsBean.getOrder_status());
        textView_add_time.setText("下单时间：" + orderDetailsBean.getAdd_time());
        if (orderDetailsBean.getPostscript() != null && orderDetailsBean.getPostscript().length() != 0) {
            textView_remarks.setVisibility(VISIBLE);
            textView_remarks.setText("备注：" + orderDetailsBean.getPostscript());
        } else {
            textView_remarks.setVisibility(GONE);
        }

        textView_call.setVisibility(GONE);
        textView_sure.setVisibility(GONE);
        textView_complete.setVisibility(GONE);
        textView_evaluate.setVisibility(GONE);
        imageView_start1.setVisibility(GONE);
        imageView_start2.setVisibility(GONE);
        imageView_start3.setVisibility(GONE);
        imageView_start4.setVisibility(GONE);
        imageView_start5.setVisibility(GONE);
        textView_tv1.setVisibility(GONE);
        linearLayout_evaluate.setVisibility(GONE);
        String status = orderDetailsBean.getStatus();
        switch (status) {
            case SERVICE:
                textView_call.setVisibility(VISIBLE);
                textView_complete.setVisibility(VISIBLE);
                break;
            case CONFIRM:
                textView_call.setVisibility(VISIBLE);
                textView_sure.setVisibility(VISIBLE);
                break;
            case COMPLETE:
                textView_call.setVisibility(VISIBLE);
                if (orderDetailsBean.getStore_grades() != null && !orderDetailsBean.getStore_grades().equals("") && !orderDetailsBean.getStore_grades().equals("0")) {
                    linearLayout_evaluate.setVisibility(VISIBLE);
                    setStart(Integer.parseInt(orderDetailsBean.getStore_grades()));
                    if (orderDetailsBean.getContent() != null && !orderDetailsBean.getContent().equals("")) {
                        textView_tv1.setVisibility(VISIBLE);
                        textView_evaluate.setVisibility(VISIBLE);
                        textView_evaluate.setText(orderDetailsBean.getContent());
                    }
                }
                break;
            case CANCEL:
                textView_call.setVisibility(VISIBLE);
                break;
        }
        textView_call.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                card.getOnNormalButtonPressedListener().onButtonPressedListener(v, card);
            }
        });
        textView_sure.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                card.getOnNormalButtonPressedListener().onButtonPressedListener(v, card);
            }
        });
        textView_complete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                card.getOnNormalButtonPressedListener().onButtonPressedListener(v, card);
            }
        });
    }

    private void setStart(int i) {
        switch (i) {
            case 0:
                break;
            case 1:
                imageView_start1.setVisibility(VISIBLE);
                break;
            case 2:
                imageView_start1.setVisibility(VISIBLE);
                imageView_start2.setVisibility(VISIBLE);
                break;
            case 3:
                imageView_start1.setVisibility(VISIBLE);
                imageView_start2.setVisibility(VISIBLE);
                imageView_start3.setVisibility(VISIBLE);
                break;
            case 4:
                imageView_start1.setVisibility(VISIBLE);
                imageView_start2.setVisibility(VISIBLE);
                imageView_start3.setVisibility(VISIBLE);
                imageView_start4.setVisibility(VISIBLE);
                break;
            case 5:
                imageView_start1.setVisibility(VISIBLE);
                imageView_start2.setVisibility(VISIBLE);
                imageView_start3.setVisibility(VISIBLE);
                imageView_start4.setVisibility(VISIBLE);
                imageView_start5.setVisibility(VISIBLE);
                break;
        }
    }
}
